<?php
App::import('Vendor','desmondpdf');

// create new PDF document
$pdf = new DESMONDPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->setPageOrientation("l");

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Desmond');
$pdf->SetTitle('Resumen de Gastos para Edificio');
$pdf->SetSubject('Resumen de Gastos para Edificio');
$pdf->SetKeywords('TCPDF, PDF, liquidacion, expensas');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
//$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', 'BI', 12);

// add a page
$pdf->AddPage();

// NON-BREAKING TABLE (nobr="true")
$ordExt=Array();
$ordExt[5]="Ordinario";
$ordExt[6]="Extraordinario";

$tbl = "<h1>Resumen de Gastos para Edificio  ";

$tbl=$tbl.$building["Building"]["building_name"]."</h1>";

$tbl=$tbl."<table cellpadding=\"2\" cellspacing=\"2\" nobr=\"true\" width=\"100%\">";
	
		$tbl=$tbl."<tr> ";	
			
		$tbl=$tbl."<td>"."<u>Tipo de Gasto</u>"."</td>"; 
		$tbl=$tbl."<td>". "<u>Documento</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Detalle</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Monto</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Tipo</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Nombre</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Dia Pago</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Metodo de Pago</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Numero Factura</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Año de prevision</u>"."</td>"; 
		$tbl=$tbl ."<td>". "<u>Mes de prevision</u>"."</td>"; 
			
			$tbl=$tbl."</tr> ";

		foreach ($building['Expenditure'] as $expenditure){
		$tbl=$tbl."<tr> ";	
			
		$tbl=$tbl."<td>". $expenditureTypeArray[$expenditure['expenditure_type_id']]."</td>"; 
		$tbl=$tbl."<td>". $expenditure['document_number']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['detail']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['amount']."</td>"; 
		$tbl=$tbl ."<td>". $ordExt[$expenditureTypeSourceArray[$expenditure['expenditure_type_id']]]."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['party_name']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['payment_date']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['payment_method']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['invoice_number']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['forecast_year']."</td>"; 
		$tbl=$tbl ."<td>". $expenditure['forecast_month']."</td>"; 
			
			$tbl=$tbl."</tr> ";
}
	

$pdf->writeHTML($tbl, true, false, false, false, '');

// ---------------------------------------------------------

//Close and output PDF document
$pdf->Output($filetmp, 'F');

?>